package com.zx.sdk.model;

import com.google.gson.Gson;
import com.zx.sdk.util.SPHelper;

import java.text.DateFormat;
import java.util.Date;

public class Winner {
    public final String league;
    public final int cpm;

    public Winner(String key, String league, int cpm) {
        this.league = league;
        this.cpm = cpm;
        SPHelper.put(key + getDate(), new Gson().toJson(this));
    }

    public static Winner load(String key) {
        try {
            return new Gson().fromJson((String) SPHelper.get(key + getDate(), ""), Winner.class);
        } catch (Exception e) {
            return null;
        }
    }

    public String getDsp() {
        return switch (league) {
            case "bd" -> "2";
            case "ks" -> "4";
            default -> "5";
        };
    }

    public String getCpm() {
        return cpm + "";
    }


    public static String getDate() {
        DateFormat dateInstance = DateFormat.getDateInstance();
        return dateInstance.format(new Date());
    }
}